package com.why.basictype;

import com.why.utils.BaseConversionUtils;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author by xiaoTian
 *@date 2022/5/20.
 *
*/
public class U2 {

    short value;

    public U2(short aByte) {
        this.value = aByte;
    }

    public static U2 read(InputStream inputStream) {
        byte[] bytes = new byte[2];
        try {
            inputStream.read(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }
        short value = BaseConversionUtils.byte2short(bytes);
        U2 u2 = new U2((short) (value & 0xFFFF));
        return u2;
    }
    public short getValue(){return this.value;}


    public String getHexValue() {
        return Integer.toHexString(value & 0xFFFF);
    }



}
